﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using AP.Framework.Infrastructure.Repositories.IRepositories;
using AP.Framework.Infrastructure.Entities;
using ApCMS.Models;

namespace ApCMS.Controllers
{
    public class NewsController : Controller
    {

        IArticleCategory _ArticleCategory;
        IArticle _Article;
        public NewsController(IArticleCategory ArticleCategory, IArticle Article)
        {
            _ArticleCategory = ArticleCategory;
            _Article = Article;
        }
        public ActionResult Index(int? categoryId)
        {
            NewsModels model = new NewsModels();
            model.ArticleCategoryList = _ArticleCategory.GetAll().OrderByDescending(p => p.ModifyTime).ToList();
            model.ArticleList = _Article.GetAll().OrderByDescending(p => p.ModifyTime).ToList();
            if (categoryId > 0) 
            {
                model.ArticleList = model.ArticleList.Where(p => p.CategoryId == categoryId);            
            }
            return View(model);
        }
        public ActionResult ViewDetails(int? articleId)
        {
            NewsModels model = new NewsModels();
            model.ArticleCategoryList = _ArticleCategory.GetAll().OrderByDescending(p => p.ModifyTime).ToList();
            model.ArticleList = _Article.GetAll().OrderByDescending(p => p.ModifyTime).ToList();
            model.Article = _Article.GetAll().Where(p => p.ID == articleId).FirstOrDefault();
            return View(model);
        }

    }
}
